<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    /**
     * forEach: 没有返回值
     * filter: 返回新数组
     */
    const arr = ['red', 'green', 'pink']
    arr.forEach(function (item, index) {
        console.log(item)  // 数组元素 red  green pink
        console.log(index) // 索引号
    })

    const arr1 = [10, 20, 30]
    const newArr = arr1.filter(function (item, index) {
      return item >= 20
    })
    // 箭头函数简写方式
    // const newArr = arr.filter(item => item >= 20)
    console.log(newArr)
</script>
</body>
</html>